<template>
	<ge-page id="ge-page" :vanNavBarObj="vanNavBarObj">
		<view>
			 
		</view> 
		<!-- <view style="width: 100%;height: 100%;background-color: #07C160;">111</view> -->
	</ge-page>
</template>

<script>
	import { storageKey } from '@/constant/config';
	export default {
		data() {
			return {
				vanNavBarObj: {
					title: '标题',
					rightText: '保存'
				}
			};
		},
		onLoad() {

		},
		created() {
			const hrefUrl = location.href;
		 
			function getUrlKey(name) {
				return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(hrefUrl) || [,
					""
				])[1].replace(/\+/g, '%20')) || null;
			}
			uni.api.storeInfo().then(res => {
				if (!res) {
					// // 未登录 
					const openid = getUrlKey('openid');
					// 如果URL 没带code跳转
					if (openid) {
							uni.api.wxlogin({
								openid: openid
							}).then((res) => { 
								if(!res.err){
									uni.setStorageSync(storageKey.token, res.token);
									uni.setStorageSync(storageKey.userId, res.userId);
									uni.setStorageSync(storageKey.storeId, res.storeId);
									uni.reLaunch({
										url: '/pages/tabbar/tabbar'
									})
								}else{
									//登录失败
									uni.showToast({
										title: '登录失败',
										duration: 2000,
										icon:'error'
									});
								}
								
							})
					}
					
				} else {
					this.storeInfo = res.storeInfo;
					uni.api.fetchHomeStat().then(({ data }) => {
						this.storeStat = data;
						uni.reLaunch({
							   url: '/pages/tabbar/tabbar'
						}) 
					})
				}
			})
		},
		methods: {
			 
		}
	}
</script>

<style>

</style>
